unit dgAddPin ;

interface

uses
   Windows,
   Messages,
   SysUtils,
   Variants,
   Classes,
   Graphics,
   Controls,
   Forms,
   Dialogs,
   SpTBXControls,
   StdCtrls,
   SpTBXEditors,
   TBXDkPanels,
   TBXExtItems,
   TB2Item,
   TBX,
   SpTBXItem,
   TB2ExtItems,
   TB2Dock,
   TB2Toolbar,
   uBasic,
   TntStdCtrls,
   uObjects,
   GDIPAPI,
   GDIPOBJ ;

type
   TdlgAddPin = class( TForm )
      Panel : TSpTBXPanel ;
      btOK : TSpTBXButton ;
      btCancel : TSpTBXButton ;
      rgDirection : TSpTBXRadioGroup ;
      SpTBXGroupBox3 : TSpTBXGroupBox ;
      seOffsetX : TSpTBXSpinEdit ;
      seOffsetY : TSpTBXSpinEdit ;
    btApply: TSpTBXButton;
    seSize: TSpTBXSpinEdit;
      procedure btOKClick( Sender : TObject ) ;
      procedure FormCreate( Sender : TObject ) ;
    procedure btApplyClick(Sender: TObject);
   private
      fPin : TMedaPin ;
      procedure SetPin( const Value : TMedaPin ) ;
      procedure SetTitle( const Value : string ) ;
   public
      property Title : string write SetTitle ;
      property Pin : TMedaPin read fPin write SetPin ;
   end ;

implementation

{$R *.dfm}
// TMedaDir = ( drEast, drNE, drNorth, drNW, drWest, drSW, drSouth, drSE ) ;

const
   DirectionIndex   : array[ TMedaDir ] of integer = (
      1, -1, 0, -1, 3, -1, 2, -1
      ) ;
   IndexDirection   : array[ 0..3 ] of TMedaDir = (
      drNorth, drEast, drSouth, drWest
      ) ;

   { TdlgAddPin }

procedure TdlgAddPin.FormCreate( Sender : TObject ) ;
begin
   fPin := nil ;
   Caption := ' New Pin' ;
end ;

procedure TdlgAddPin.SetPin( const Value : TMedaPin ) ;
begin
   fPin := Value ;
   if assigned( fPin ) then begin
      seOffsetX.Value := fPin.Offset.X ;
      seOffsetY.Value := fPin.Offset.Y ;
      rgDirection.ItemIndex := DirectionIndex[ fPin.Direction ] ;
      seSize.Value := fPin.Size ;
   end ;
end ;

procedure TdlgAddPin.SetTitle( const Value : string ) ;
begin
   Caption := Value ;
end ;

procedure TdlgAddPin.btApplyClick(Sender: TObject);
begin
   if assigned( fPin ) then begin
      fPin.Direction := IndexDirection[ rgDirection.ItemIndex ] ;
      fPin.Size := seSize.ValueAsInteger ;
      fPin.Offset := MakePoint( seOffsetX.Value, seOffsetY.Value ) ;
   end ;
end;

procedure TdlgAddPin.btOKClick( Sender : TObject ) ;
begin
   if assigned( fPin ) then begin
      fPin.Direction := IndexDirection[ rgDirection.ItemIndex ] ;
      fPin.Size := seSize.ValueAsInteger ;
      fPin.Offset := MakePoint( seOffsetX.Value, seOffsetY.Value ) ;
   end ;
end ;

end.

